<?php 
include_once ('../global.php');

$groups = selGroupName($mt_id);

foreach($groups as $g => $value){
	if($lang == 'CN'){
		$groupname  = $value['name'];	
		$groupname = str_replace("A", '<font class="poppin" >A</font>', $groupname);
		$groupname = str_replace("B", '<font class="poppin" >B</font>', $groupname);
		$groupname = str_replace("C", '<font class="poppin" >C</font>', $groupname);
		$grouptype[$value['id']] = 	$groupname;
	}
	else {
		$grouptype[$value['id']] = $value['name_en'];		
	}
}
if($mt_id == 4400){
$matcheventdata = array(
    1 => '2024-11-26',
    2 => '2024-11-27',
    3 => '2024-11-28'
);
}
if($mt_id == 4579){
$matcheventdata = array(
    1 => '2024-12-11',
    2 => '2024-12-12',
    3 => '2024-12-13'
);
}

$biaoji = isset($_GET['biaoji']) ? $_GET['biaoji'] : "";
$maxRound = 3;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">

<script type="text/javascript" src="<?php echo JS_PATH?>jquery-1.8.3.min.js"></script>
<link href="<?php echo CSS_PATH?>index.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="<?php echo JS_PATH?>main.js"></script>
<title class="<?php echo $css_class; ?>"><?php echo t('group_table'); ?>-<?php echo $match_cn_name?>-<?php echo t('scoring_by_scoring_cloud_technology'); ?></title>
<script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
 
<script>
    var url = location.href; 
    var wxdata;
    console.log(url.replace(/\&/g, "%26").replace(/\#/g, "%23"));
    $.ajax({
        type: "get",
        url: "../../interface/joysports/Home/gettoken/?url=" + encodeURIComponent(location.href.split('#')[0]),
        dataType: "jsonp",
        jsonp: "callback",
        jsonpCallback: "success_jsonpCallback",
        success: function(data){
            console.log(data);
            wxdata = data;
            wx.config({
                debug: false,
                appId: data.appId,
                timestamp: data.timestamp,
                nonceStr: data.nonceStr,
                signature: data.signature,
                jsApiList: [
                    'updateAppMessageShareData',
                    'updateTimelineShareData'
                ]
            });
            wx.ready(function () {
                var shareData = {
                    title: '<?php echo $match_cn_name?>-<?php echo t('live_score'); ?>-<?php echo t('scoring_by_scoring_cloud_technology'); ?>',
                    desc: '<?php echo $course_name?>-<?php echo t('scoring_by_scoring_cloud_technology'); ?>',
                    link: url,
                    imgUrl: 'https://mapp.scoringchina.com/bmwjunior/mobile/images/logo.png'
                };
                wx.updateAppMessageShareData(shareData); // 分享给好友
                wx.updateTimelineShareData(shareData); // 分享到朋友圈
                wx.onMenuShareQQ(shareData); // 分享给手机QQ
                wx.onMenuShareWeibo(shareData); // 分享腾讯微博
                wx.onMenuShareQZone(shareData); // 分享到QQ空间
            });
            wx.error(function (res) {
                console.log(res);
                // alert(res.errMsg); // 错误提示
            });
        },
        error: function(data){
            console.log(data);
            alert(t('connection_failed'));
        }
    });
	
	/*  滚动到顶部*/
    $(function () {
        $("#go_top").hide();
        $('#content_score').height($(window).height() - 120 - 50);
    });
 
    // scroll() 方法为滚动事件  
    $(window).scroll(function(){
        if ($(window).scrollTop() > 100){
            $("#go_top").fadeIn(800);
        } else{
            $("#go_top").fadeOut(800);
        }
    });
 
    function gotomain(){
        window.location = './main.php';
    }
    
    function goback(){
        var biaoji = '<?php echo $biaoji; ?>';
        window.location = './index.php?biaoji=' + biaoji;
    }
  
    function gotottop(){
        $('body,html').animate({scrollTop:0}, 100);
        return false;
    }
</script>
<style>
#sta{
    position: relative;
    z-index: 99;
    height: 80px;
    width: 100%;
    background-color: transparent;
    left: 0;
    top: 0;
}
.up{
    width: 40px;
    height: 40px; 
    position: fixed; 
    left: 2vw;
    bottom: 5vw;
}
.radius_fillet3 {
    border-radius: 3px;
}
.tt_bar {
    height: auto;
}
.score_title2 {
    height: 30px;
    border-bottom: 1px solid #e3e3e3;
    text-indent: 14px;
}
.score_back {
    text-align: right;
    padding-right: 14px;
}
.bt_back {
    display: inline-block;
    width: 40px;
    height: 18px;
    line-height: 18px;
    cursor: pointer;
    border: 1px solid #363636;
    color: #363636;
    font-size: 12px;
    text-align: center;
}
.score_tround {
    height: 30px;
    line-height: 30px;
}
.score_tround span {
    color: #363636;
    float: right;
    font-size: 18px;
    height: 26px;
    line-height: 32px;
    margin-right: 15px;
    text-align: center;
    width: 50px;
}
.index_news {
    padding: 0 15px;
}

.content_score{
    margin: 15px 15px 0 15px;
    border:1px solid #fff;
    overflow-y:scroll;
    position:relative;
    margin-top:10px;
}

a{
    text-decoration:none;
}
</style>
<style>
#content {
    padding-top: 10px;
    padding-left: 15px;
    padding-right: 15px;
    padding-bottom: 40px;
    max-height: 100vh;	
}

#navi_wait {
    height: 35px;
    background-color: #E3E3E3;
}

#navi_wait ul li {
    width: 32%;
    display: inline;
    float: left;
    line-height: 36px;
    list-style-position: inside;
    border-bottom: 1px solid #A5A5A5;
    text-align: center;
}

#navi_wait ul li a {
    color: #767676;
    font-size: 19px;
    letter-spacing: 5px;
}

.topar{
    width:90%;
    height:25px;
    border-radius:10px;
    margin:auto auto auto auto;
    color:#fff;
    display:flex;
    justify-content:center;
    align-items:center;
}
.undereven{
    font-weight:bolder;
    background-color:#B7001F;
    color:#fff;
}
.even{
    font-weight:bolder;
    background-color:#53565A;
    color:#fff;
}
.pluseven{
    font-weight:bolder;
    background-color:#00438A;
    color:#fff;
}

.score_round{
    float: right;
    height:auto;
    width: 100%;
    margin-top:5px;
    margin-bottom:5px;
    display:flex;
    flex-direction:row;
    align-items:center;
    justify-content:flex-end;
}
.score_round span{
    text-align: center;
    width: 50px;
    line-height: 32px;
    height:auto;
    float: right;
    margin-right:15px ;
    font-size: 18px;
    color: #000;
}
.score_round span a:link, 
.score_round span a:visited, 
.score_round span a:hover{
    color: #000;
}

.scoringtable{
    border-collapse: collapse;  
    border-style:hidden; 
    /*background:linear-gradient(145deg, #000519, #095557);*/
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    border-collapse: collapse;
    font-size:14px;
    color:#fff;
    position:relative;
    margin-top:40px;
    left:0;
    border: none;
    width:100%;
}

th, td {
    border-left: none;
    border-right: none;
}

.scoringtable tr{
    background-color:transparent;
    height:30px;
}

.scoringtable td{
    text-align:center;
    font-size:16px;
}
/* 样式用于表头行 */
.header-row {
    border-top: 1px solid #fff;
    border-bottom: 1px solid #fff;
    color: #fff;
    background: linear-gradient(0deg, rgb(3, 40, 60), rgb(7, 77, 82));
    font-size: 10px;
}

/* 样式用于“球员”列 */
.player-column {
    text-align: left;
    padding-left: 5px;
}
</style>

</head>
<body id="body">

<div id="sta">
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tbody>
            <tr>
                <td style="text-align:center;"><img src="./images/000.png" style="width:350px;height:80px" /></td>
            </tr>
        </tbody>
    </table>
</div>

<div id="content_score" class="content_score">
    <div class="tt_bar" style="display:none;">
        <table class="altrowstable scoringtable" border="0" cellpadding="0" cellspacing="0" width="100%">
            <tbody>
                <tr>
                    <td style="border:none; vertical-align:middle;">
                        <font style="font-weight:bolder;font-size:17px;" ><?php echo $match_cn_name?></font>
                    </td>
                </tr>
                <tr>
                    <td style="border:none; vertical-align:middle;float:right">
                        <span style="margin-right:10px;" class="bt_back radius_fillet3" class="">
                            <a href="index.php?mt_id=<?php echo $mt_id?>&baoji=<?php echo $baoji?>"><?php echo t('back'); ?></a>
                        </span>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <div class="tt_bar" style="display:block;">
        <div style="width:100%;text-align:center;margin-top:5px;">
            <font style="font-weight:500;font-size:14px;" class="<?php echo  $css_class ; ?>"><?php echo $course_name?></font>
        </div>
        <div style="width:100%;text-align:center;margin-top:5px;">
            <font style="font-weight:400;font-size:12px;" class="poppin"><?php echo $matcheventdata[$rd_id]?></font>
        </div>
    </div>
   
		<?php
if($mt_round >=1) {  
    echo '<div class="score_round">';
    // 添加 class 属性到第一个 <span>
    echo '<span class="' . htmlspecialchars($css_class, ENT_QUOTES, 'UTF-8') . '" style="float:left;width:auto;color:#fff;font-size:12px;margin-right:auto;text-align:left;padding-left:5px;">' . t('click_player_for_details') . '</span>';
    for($i = $maxRound; $i >= 1; $i--){
        // 添加 class 属性到循环中的 <span>
        echo '<span class="' . htmlspecialchars($css_class, ENT_QUOTES, 'UTF-8') . ' poppin" style="border-radius:100%;width:40px;height:40px;display:flex;align-items:center;justify-content:center;' . (($i == $rd_id) ? 'background-color:#095557;color:#fff;' : 'color:#fff;') . '">
                <a  class="poppin" href="?mt_id=' . urlencode($mt_id) . '&rd_id=' . urlencode($i) . '&biaoji=' . urlencode($biaoji) . '" style="color:#fff;">
                    ' . t('roundR') . $i . '
                </a>
              </span>';
    }	
    echo '</div>';
}
?>
    
    <table class="altrowstable scoringtable">
        <tbody>
<?php
function group_detail($mt_id, $rd_id){
    global $db, $dbprefix;
    $sql = "SELECT gp_id, gp_seq, gp_start_time, gp_start_hole, gpd_line, gpd_player 
            FROM `group` as gp LEFT JOIN `group_detail` as gd ON gp.gp_id = gd.gpd_id 
            WHERE gp_mt_id = '".$mt_id."' AND gp_rd_id = '".$rd_id."' ORDER BY gp_seq, gpd_line ASC ";
    $res = $db->SelectSQL($sql);
    $num = count($res);
    if ($num > 0){
        foreach ($res as $i => $n){
            $arr[$n['gp_seq']]['seq'] = $n['gp_seq'];
            $arr[$n['gp_seq']]['time'] = $n['gp_start_time'];
            $arr[$n['gp_seq']]['tee'] = $n['gp_start_hole'];
            $arr[$n['gp_seq']]['player'][$n['gpd_line']] = $n['gpd_player'];
        }
    }
    return $arr;
}
$groups = group_detail($mt_id, $rd_id);
//$holeScore = getHoleScore($mt_id, $rd_id); //当前洞和当前轮的topar
$score = getScore($mt_id); //比赛成绩读取

for ($r = 1; $r <= $mt_round; $r++){
    if (!empty($score['to_par'])){
        foreach ($score['to_par'] as $k => $v){
            $topar[$k] += $v[$r];
        }
    }
}

function getplayername($players,$pl_id,$lang,$isshort=0){
	if($lang == 'CN'){
		return $players['playerName'][$pl_id];
	}
	else{
		if($isshort){
			return $players['playerEnshortName'][$pl_id];
		}
		else{
			return $players['playerEnName'][$pl_id];
		}
	}
}

if ($groups){
    $index = 0;
    foreach ($groups as $i => $n){
        $count = count($n['player']);
        if ($count > 0){
					if($index == 0 ){
						echo '<tr class="' . htmlspecialchars($css_class, ENT_QUOTES, 'UTF-8') . ' header-row">
										<th>' . t('group_number') . '</th>
										<th>' . t('tee') . '</th>
										<th>' . t('start_time') . '</th>
										<th class="player-column">' . t('player') . '</th>
										<th>' . t('score') . '</th>
										<th>' . t('group_type') . '</th>
								</tr>';
				}
            for ($a = 1; $a <= $count; $a++){
                echo '<tr ' . ($a == $count ? 'style="border-bottom:1px solid #fff;font-size:12px;"' : 'style="font-size:13px;"') . '>';
                if ($a == 1){
                    echo '<td width="8%" class="poppin" rowspan="' . $count . '">' . $n['seq'] . '</td>';
                    echo '<td width="15%" class="poppin" rowspan="' . $count . '">' . $n['tee'] . '</td>';
                    echo '<td width="18%" class="poppin" rowspan="' . $count . '">' . substr($n['time'], 10,6) . '</td>';
                }	
                echo '<td width="22%" class="poppin" align="left" style="text-align: left; display:table-cell; vertical-align:middle; padding-left:5px;
                max-width: 100px; /* 设置最大宽度 */
                overflow: hidden; /* 隐藏超出部分 */
                white-space: nowrap; /* 禁止换行 */
                text-overflow: none; /* 超出部分显示省略号 */
                transition: font-size 0.3s; /* 字体大小变化过渡效果 */
                font-size: 13px;">
                        <a href="detail.php?mt_id=<?php echo $mt_id; ?>&pl_id=' . $n['player'][$a] . '&biaoji=<?php echo $biaoji; ?>"><span style="color:#fff" class="' . $css_class . '">' . getplayername($players,$n['player'][$a],$lang,0) . '&nbsp;&nbsp;</span></a>
                    </td>';

                echo '<td width="10%" class="poppin">
                        <div style="font-size:13px;font-weight:500;" class="topar ' . 
                            (($topar[$n['player'][$a]] < 0) ? 'undereven' : (($topar[$n['player'][$a]] == 0) ? 'even' : (($topar[$n['player'][$a]] > 0) ? 'pluseven' : ''))) . 
                            '">' . 
                            (($topar[$n['player'][$a]] > 0) ? '+' : '') . 
                            (($topar[$n['player'][$a]] == '0') ? 'E' : $topar[$n['player'][$a]]) . 
                        '</div>
                    </td>';
                
                echo '<td width="17%" class="' . $css_class . '" style="font-size:13px;">' . $grouptype[$players['playerClass'][$n['player'][$a]]] . '</td>';
                
                echo '</tr>';
            }
            
            $index++;
        }
    }
}
?>				
        </tbody>
    </table>

</div>

<div class="bottommenu">
    <div class="<?php echo $css_class; ?>" onclick="goback()"><?php echo t('back'); ?></div> 
    <?php if(empty($biaoji)){?>
        <div class="<?php echo $css_class; ?>" onclick="gotomain()"><?php echo t('home_page'); ?></div>
    <?php } ?>
</div>
<img src="images/up.png" class="up" id="go_top" onclick="gotottop();">
<div id="bottom" style="background-color:transparent;text-align:center;display:none;justify-content: center;">
    <div id="bootom-top">
        <span style="width:100%;text-align:center"><?php echo t('technical_support'); ?></span>
        <script charset="UTF-8" id="LA_COLLECT" src="//sdk.51.la/js-sdk-pro.min.js"></script>
        <script>
            LA.init({id: "JijETG4HGxctAarj", ck: "JijETG4HGxctAarj"})
        </script>
    </div>
</div>
</body>
</html>